<template>
  <div class="container">
    <p>objA:{{objA}}</p>
    <p>objB:{{objB}}</p>
    <p>isEqual:{{isEqual}}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      objA: {},
      objB: {},
      isEqual: false
    };
  },
  created() {
    this.loadData();
  },
  mounted() {},
  methods: {
    /*
    loadData(){
      let objA = {
        a: 1,
        b: 2,
        c:{
            age:3
        }
      },
      objB = {
        a: 1,
        b: 2,
        c:{
            age:3
        }
      },
      isEqual = false

      isObjectValueEqual(objA,objB)

      function isObjectValueEqual(a, b) {
        var aProps = Object.getOwnPropertyNames(a);
        var bProps = Object.getOwnPropertyNames(b);
        if (aProps.length != bProps.length) {
          isEqual = false
          return false;
        }
        for (var i = 0; i < aProps.length; i++) {
          var propName = aProps[i];
          var propA = a[propName];
          var propB = b[propName];
          if ( propA !== propB) {
            isEqual = false
            return false;
          }
        }
        isEqual = true
        return true;
      }
      this.isEqual = isEqual
      this.objA = objA
      this.objB = objB
    },
    */
    loadData() {
      let isEqual = false;
      function isObjectValueEqual(a, b) {
        console.log(a,b,'??ab');
        
        var aProps = Object.getOwnPropertyNames(a);
        var bProps = Object.getOwnPropertyNames(b);
        if (aProps.length != bProps.length) {
          isEqual = false;
          return false;
        }
        for (var i = 0; i < aProps.length; i++) {
          var propName = aProps[i];

          var propA = a[propName];
          var propB = b[propName];
          if (typeof propA === "object") {
            if (isObjectValueEqual(propA, propB)) {
              // return true     这里不能return ,后面的对象还没判断
            } else {
              isEqual = false;
              return false;
            }
          } else if (propA !== propB) {
            isEqual = false;
            return false;
          } else {
          }
        }
        isEqual = true;
        return true;
      }
      var a = {
        id: 1,
        name: 2,
        c: {
          age: 3
        }
      };
      var b = {
        id: 1,
        name: 2,
        c: {
          age: 3
        }
      };
      this.objA = a;
      this.objB = b;
      this.isEqual = isEqual;
      // isObjectValueEqual(a, b)
    }
  }
};
</script>
<style>
</style>